package com.java.service;

import com.java.context.AuthContext;
import com.java.model.AdminUser;
import com.java.vo.Result;
/**
 * 判断用户名及密码是否正确
 */
public class LoginService {
	
	public Result login(String username, String password) {
		Result result = new Result();
		AdminUser admin = null;
		try {
			admin = AdminUser.valueOf(username);
		} catch (Exception e) {
		}
		
		if (admin == null) {
			return result.fail("用户不存在");
		}
		if (!admin.getPassword().equals(password)) {
			return result.fail("用户名密码不正确");
		}
		AuthContext.setCurrentUser(admin);
		return result.success("恭喜您，登录成功");
	}
	
	/**
	 * 注销用户
	 */
	public Result logout() {
		AuthContext.setCurrentUser(null);
		Result result = new Result();
		return result.success("恭喜您，登出成功");
	}

}
